prepare-root: Move metadata for deployment into otcore
authorColin Walters <walters@verbum.org>
Tue, 24 Jun 2025 20:08:29 +0000 (16:08 -0400)
committerColin Walters <walters@verbum.org>
Tue, 24 Jun 2025 20:39:14 +0000 (16:39 -0400)
- Rename `mount_composefs` to `mount_rootfs` to make a little clearer
  what it does; even though if the rootfs is not composefs we don't
  do anything before.
- But do always unconditionally update the metadata builder with
  the device/inode

Prep for soft reboots.

Signed-off-by: Colin Walters <walters@verbum.org>
src/libotcore/otcore-prepare-root.c
src/libotcore/otcore.h
src/switchroot/ostree-prepare-root.c

index fa990dec20b7f34b9d65f09757851d50d19a9c13..a82e16d28fd903100c7eca2d629ce210b37dde7e 100644 (file)
@@ -363,11 +363,20 @@ composefs_error_message (int errsv)
 #endif
 
 gboolean
-otcore_mount_composefs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder,
-                        gboolean root_transient, const char *root_mountpoint,
-                        const char *deploy_path, const char *mount_target,
-                        bool *out_using_composefs, GError **error)
+otcore_mount_rootfs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder,
+                     gboolean root_transient, const char *root_mountpoint, const char *deploy_path,
+                     const char *mount_target, bool *out_using_composefs, GError **error)
 {
+  struct stat stbuf;
+  /* Record the underlying plain deployment directory (device,inode) pair
+   * so that it can be later checked by the sysroot code to figure out
+   * which deployment was booted.
+   */
+  if (lstat (deploy_path, &stbuf) < 0)
+    return glnx_throw_errno_prefix (error, "lstat(%s)", deploy_path);
+  g_variant_builder_add (metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_BACKING_ROOTDEVINO,
+                         g_variant_new ("(tt)", (guint64)stbuf.st_dev, (guint64)stbuf.st_ino));
+
   bool using_composefs = FALSE;
 #ifdef HAVE_COMPOSEFS
   /* We construct the new sysroot in /sysroot.tmp, which is either the composefs
index 7a9978de9df6e12c469cde815c66d5a1a3f4e795..378878df3fcf8351f584b3ddfbf594f24e0d6d1d 100644 (file)
@@ -79,7 +79,7 @@ ComposefsConfig *otcore_load_composefs_config (const char *cmdline, GKeyFile *co
                                                gboolean load_keys, GError **error);
 
 /**
- * otcore_mount_composefs:
+ * otcore_mount_rootfs:
  * @composefs_config: Configuration for composefs.
  * @metadata_builder: (transfer none): GVariantBuilder to add metadata to.
  * @root_transient: Whether the root filesystem is transient.
@@ -89,15 +89,15 @@ ComposefsConfig *otcore_load_composefs_config (const char *cmdline, GKeyFile *co
  * @out_using_composefs: (out): Whether composefs was successfully used.
  * @error: (out): Return location for a GError, or %NULL.
  *
- * Mounts a composefs image based on the provided configuration.
+ * If composefs is enabled, it will be mounted at the target. Otherwise, the
+ * target directory is left unchanged.
  *
  * Returns: %TRUE on success, %FALSE on error.
  */
-gboolean otcore_mount_composefs (ComposefsConfig *composefs_config,
-                                 GVariantBuilder *metadata_builder, gboolean root_transient,
-                                 const char *root_mountpoint, const char *deploy_path,
-                                 const char *mount_target, bool *out_using_composefs,
-                                 GError **error);
+gboolean otcore_mount_rootfs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder,
+                              gboolean root_transient, const char *root_mountpoint,
+                              const char *deploy_path, const char *mount_target,
+                              bool *out_using_composefs, GError **error);
 
 // Our directory with transient state (eventually /run/ostree-booted should be a link to
 // /run/ostree/booted)
index d3dee902aea67f548720f2ef369ae850bc6bd95e..fb38f095777adf23708219e6f915f66e0f103065 100644 (file)
@@ -263,19 +263,10 @@ main (int argc, char *argv[])
   GVariantBuilder metadata_builder;
   g_variant_builder_init (&metadata_builder, G_VARIANT_TYPE ("a{sv}"));
 
-  /* Record the underlying plain deployment directory (device,inode) pair
-   * so that it can be later checked by the sysroot code to figure out
-   * which deployment was booted.
-   */
-  if (lstat (".", &stbuf) < 0)
-    err (EXIT_FAILURE, "lstat deploy_root");
-  g_variant_builder_add (&metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_BACKING_ROOTDEVINO,
-                         g_variant_new ("(tt)", (guint64)stbuf.st_dev, (guint64)stbuf.st_ino));
-
   // Tracks if we did successfully enable it at runtime
   bool using_composefs = false;
-  if (!otcore_mount_composefs (composefs_config, &metadata_builder, root_transient, root_mountpoint,
-                               deploy_path, TMP_SYSROOT, &using_composefs, &error))
+  if (!otcore_mount_rootfs (composefs_config, &metadata_builder, root_transient, root_mountpoint,
+                            deploy_path, TMP_SYSROOT, &using_composefs, &error))
     errx (EXIT_FAILURE, "Failed to mount composefs: %s", error->message);
 
   if (!using_composefs)